package com.cloudbroker.bcs.platform.dav.bizapi.constants.type;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public enum TermType {

	ALL(123,"通用","1,2,3,"),
	PC(1, "PC端","1,"),
	APP(2, "APP端","2,"),
	FANS(3, "粉丝端","3,"),
	PCAPP(12, "PC端和APP端","1,2,"),
	PCFANS(13, "PC端和粉丝端","1,3,"),
	APPFANS(23, "APP和粉丝端","2,3,")
	;

	private final int val;

	private final String description;
	
	private final String dbStr;

	private TermType(int val, String description,String dbStr) {
		this.val = val;
		this.description = description;
		this.dbStr = dbStr;
	}

	public int getVal() {
		return val;
	}

	public String getDescription() {
		return description;
	}
	
	public String getDbStr() {
        return dbStr;
    }

	public static String getDbStr(String val){
	    int nomalNum = Integer.parseInt(val);
	    int reverseNum = Integer.parseInt(new StringBuffer(val).reverse().toString());
	    for (TermType t : TermType.values()) {
            if(t.getVal() == nomalNum || t.getVal() == reverseNum){
                return t.dbStr;
            }
        }
	    return "";
	}
	
	public static boolean checkTermTypeStr(String str){
        Pattern pattern = Pattern.compile("(1,)?(2,)?(3,)?");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
	}
	
}
